import mysql.connector
#省内外人数分布统计
def isSN(sumR):
    # 打开数据库连接
    db = mysql.connector.connect(
        host="124.222.244.117",  # 数据库主机地址
        user="zrgj9",  # 用户名
        passwd="zrgj9",  # 密码
        database="zrgj9"
    )
    # 使用cursor()方法获取操作游标
    mycursor = db.cursor()
    # SQL 查询语句
    sql = """SELECT isGZ,
            count(stuName) 该专业人数
            from student
            where register=1 AND isGZ = '贵州'
            group by isGZ"""
    try:
        # 执行sql语句
        mycursor.execute(sql)
        data = mycursor.fetchall()
        # 提交到数据库执行
        db.commit()
       
    except:
        # 如果发生错误则回滚
        db.rollback()
    for i in range(len(data)):
        data[i] = list(data[i])
        
    shengWai = sumR - data[0][1]
    a = round((data[0][1]/sumR)*100,2)
    data1 = []
    dict = {}
    dict["x"] = data[0][1]
    dict["percent"] = a
    dict["y"] = "贵州省"
    data1.append(dict)
    dict = {}
    dict["x"] = shengWai
    dict["percent"] = round((shengWai/sumR)*100,2)
    dict["y"] = "其他省市"
    data1.append(dict)
    return data1